/**
 * Created by vincent on 2017/10/12.
 */
moduleStudyMap.controller("BadgePageController", function ($scope, $log, $state, LoadingService, ConstantService, DialogService, BadgeResource) {
    $scope.$on("$viewContentLoaded", function () {
        pageOnLoad();
        $scope.currentState = $state.current;
        ConstantService.addState($state.current, true);
        $scope.pagination = new Pagination();
        $scope.pagination.setPageClickFn($scope.queryBadge);
        $scope.queryBadge($scope.pagination.currentPageNo);
    });

    $scope.queryPara = {};
    $scope.queryBadge = function (pageNo) {
        //LoadingService.show();
        BadgeResource.queryPage({pageNo: pageNo - 1, pageSize: 10}, $scope.queryPara, function (queryResult) {
            $log.debug("勋章查询结果", queryResult);
            $scope.queryResult = queryResult;
            $scope.pagination.setPage(queryResult, pageNo);
            //LoadingService.hide();
        });
    };

    $scope.addBadge = function () {
        DialogService.open("addBadge");
    };

    $scope.editBadge = function (badge) {
        $scope.currentBadge = badge;
        //LoadingService.show();
        BadgeResource.findById({badgeId: badge.badgeId}, function (badgeResult) {
            $log.debug("勋章搜索结果", badgeResult);
            $scope.editingBadge = badgeResult;
            //LoadingService.hide();
            DialogService.open("editBadge", $scope);
        }, function () {
            //LoadingService.hide();
        });
    };

    $scope.refresh = function () {
        $scope.queryPara = {};
    };

});